<!--
 * @Author: Z.MingYu
 * @Date: 2025-05-16 15:00:54
 * @Description: 表格主体
-->

<template>
  <table>
    <colgroup>
      <col v-for="col in columns" :key="col.name" :width="col.width" />
    </colgroup>
    <tbody>
      <tr v-for="(row, i) in dataset" :key="i">
        <td v-for="col in columns" :key="col.name" :style="{ textAlign: col.align }">
          {{ renderValue(row[col.name], row, col, i) }}
        </td>
      </tr>
    </tbody>
  </table>
</template>

<script>
export default {
  name: 'ez-table-body',
  props: {
    columns: {
      type: Array[Object],
      default: []
    },
    dataset: {
      type: Array[Object],
      default: () => []
    }
  },
  methods: {
    renderValue(val, row, col, ind) {
      const formatter = col.formatter;
      if (!!formatter && typeof formatter === 'function') return formatter(val, row, col, ind);
      else return val;
    }
  }
};
</script>
